define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {

    var Controller = {
        index : function () {
            $("input:radio[name='row[auto]']").change(function (){
                var auto=$("input:radio[name='row[auto]']:checked").val();
                if(auto == 1){
                    $('.auto').show();
                }else{
                    $('.auto').hide();
                }

            }).trigger('change');
            $("input:radio[name='row[level]']").change(function (){
                var level=$("input:radio[name='row[level]']:checked").val();
                if(level == 1){
                    $('.level').show();
                }else{
                    $('.level').hide();
                }

            }).trigger('change');

            //微信小程序
            $(document).on('click', '.wxprogram', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/wxprogram", '微信小程序', options);
            });
            $(document).on('click', '.weixin', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/weixin", '微信公众号', options);
            });
            $(document).on('click', '.sea', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/sea", '公海规则', options);
            });
            $(document).on('click', '.examine', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/examine", '客户到期提醒', options);
            });
            $(document).on('click', '.feedback', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/feedback", '反馈间隔提醒', options);
            });
            $(document).on('click', '.map', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/map", '腾讯地图', options);
            });
            $(document).on('click', '.baidu', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/baidu", '百度OCR', options);
            });
            $(document).on('click', '.textin', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/textin", 'TextIn名片识别', options);
            });
            $(document).on('click', '.juhe', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/juhe", '工商信息', options);
            });
            $(document).on('click', '.users', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/user", '客户端设置', options);
            });
            $(document).on('click', '.logist', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/logist", '物流设置', options);
            });
            $(document).on('click', '.emails', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/email", '企业邮箱设置', options);
            });
            //企业微信
            $(document).on('click', '.wework', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/wework", '企业微信', options);
            });
            //钉钉
            $(document).on('click', '.dingding', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/dingding", '钉钉', options);
            });
            //线索规则
            $(document).on('click', '.leads', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/leads", '线索池分配规则', options);
            });
            //手机号是否重复
            $(document).on('click', '.phones', function (data) {
                var area = [$(window).width() > 1200 ? '800px' : '50%', $(window).height() > 800 ? '600px' : '50%'];
                var options = {
                    shadeClose : false,
                    shade      : [0.3, '#393D49'],
                    area       : area,
                    callback   : function (value) {
                    }
                };
                Fast.api.open("qingdongwms/general/adminconfig/phones", '手机号查重', options);
            });
            Form.api.bindevent($("form[role=form]"));
        },
        wechat : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        wework : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        dingding : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        wxprogram : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        weixin : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        sea : function () {
            $("input:radio[name='row[auto]']").change(function (){
                var auto=$("input:radio[name='row[auto]']:checked").val();
                if(auto == 1){
                    $('.auto').show();
                }else{
                    $('.auto').hide();
                }

            }).trigger('change');

            $("input:checkbox[name='row[genjing]']").change(function (){
                var auto=$("input:checkbox[name='row[genjing]']:checked").val();
                if(auto == 1){
                    $('.genjing').show();
                }else{
                    $('.genjing').hide();
                }

            }).trigger('change');
            $("input:checkbox[name='row[chengjiao]']").change(function (){
                var auto=$("input:checkbox[name='row[chengjiao]']:checked").val();
                if(auto == 1){
                    $('.chengjiao').show();
                }else{
                    $('.chengjiao').hide();
                }

            }).trigger('change');
            Form.api.bindevent($("form[role=form]"));
        },
        examine : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        feedback : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        map : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        baidu : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        textin : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        juhe : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        phones : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        leads : function () {
            $("input:radio[name='row[leadauto]']").change(function (){
                var auto=$("input:radio[name='row[leadauto]']:checked").val();
                if(auto == 1){
                    $('.leadauto').show();
                }else{
                    $('.leadauto').hide();
                }

            }).trigger('change');

            Form.api.bindevent($("form[role=form]"));
        },
        user : function () {
            $("#fachoose-map").on('click', function () {
                parent.Fast.api.open("qingdongwms/customer/customer/map", __('Choose'), {
                    callback: function (data) {
                        var lng = $('#lng').val(data.lng);
                        var lat = $('#lat').val(data.lat);
                        var address = $('#address').val(data.addr);
                    }
                });
                return false;
            });
            Form.api.bindevent($("form[role=form]"));
        },
        logist : function () {
            Form.api.bindevent($("form[role=form]"));
        },
        email : function () {
            Form.api.bindevent($("form[role=form]"));
        },
    };
    return Controller;
});